package day1103.demo04;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/3 10:24
 */

public class Test {
    public static void main(String[] args) {
       List<classMates> list = new ArrayList<>();
        list.add(new classMates("宝强",12));
        list.add(new classMates("马蓉",19));
        list.add(new classMates("晓明",60));
        list.add(new classMates("杨颖",56));
       Comparator<classMates> comparator=(o1, o2) -> {
           return o1.getAge()- o2.getAge();
       };
        Collections.sort(list,comparator);
        System.out.println("list = " + list);
    }
}
class classMates{
    private  String name;
    private int age;

    public classMates(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "classMates{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
